/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package lpii.clases;

import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author
 */
public class Planilla {

    private Calendar fecha;
    private DiaPago[] diaPagos;
    private int k;

    public DiaPago[] getDiaPagos() {
        return diaPagos;
    }

    public void setDiaPagos(DiaPago[] diaPagos) {
        this.diaPagos = diaPagos;
    }

    public Calendar getFecha() {
        return fecha;
    }

    public void setFecha(Calendar fecha) {
        this.fecha = fecha;
    }

    public int getK() {
        return k;
    }

    public void setK(int k) {
        this.k = k;
    }

    public Planilla() {
        diaPagos = new DiaPago[200];
        k=0;
    }
    
    public Planilla(Calendar fecha) {
        this.fecha = fecha;
        diaPagos = new DiaPago[200];
        k=0;
    }

    

    public void EscribirPlanilla() {
        SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
        FileWriter fr;
        try {
            fr = new FileWriter("Planillas/"+sdf.format(this.fecha.getTime()) + ".dat");
            PrintWriter pr = new PrintWriter(fr);
            sdf = new SimpleDateFormat("HH:mm");
            for (int i = 0; i < k; i++) {
                if (diaPagos != null) {
                    pr.write(diaPagos[i].getDniEmpleado() + "," + sdf.format(diaPagos[i].getHoraIngreso().getTime()) + "," + sdf.format(diaPagos[i].getHoraSalida().getTime()) + "\n");
                } else {
                    pr.write(diaPagos[i].getDniEmpleado() + ",,");
                }
            }
            pr.close();
        } catch (IOException ex) {
            Logger.getLogger(Planilla.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
